package com.ruoyi.community.controller.wxApi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.community.domain.Notice;
import com.ruoyi.community.service.INoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公告广告新闻Controller
 *
 * @author wj
 * @date 2022-02-22
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/wx/community/notice")
@Api(tags = {"公告广告新闻"})
public class WxNoticeController extends BaseController
{
    @Autowired
    private INoticeService noticeService;

    /**
     * 查询公告广告新闻列表
     */
    @ApiOperation(value = "查询公告广告新闻列表")
    @GetMapping("/list")
    public TableDataInfo list(Notice notice)
    {
        startPage();
        List<Notice> list = noticeService.selectNoticeList(notice);

        if (ObjectUtils.isEmpty(list)){
            return getNoDataTable(list);
        }
        return getDataTable(list);
    }

    /**
     * 导出公告广告新闻列表
     */
    @ApiOperation(value = "导出公告广告新闻列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notice notice)
    {
        List<Notice> list = noticeService.selectNoticeList(notice);
        ExcelUtil<Notice> util = new ExcelUtil<Notice>(Notice.class);
        util.exportExcel(response, list, "公告广告新闻数据");
    }

    /**
     * 获取公告广告新闻详细信息
     */
    @ApiOperation(value = "获取公告广告新闻详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo( Long id)
    {
        return AjaxResult.success(noticeService.selectNoticeById(id));
    }

    /**
     * 新增公告广告新闻
     */
    @ApiOperation(value = "新增公告广告新闻")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Notice notice)
    {
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改公告广告新闻
     */
    @ApiOperation(value = "修改公告广告新闻")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Notice notice)
    {
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除公告广告新闻
     */
    @ApiOperation(value = "删除公告广告新闻")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        Long[] ids= {id};
        return toAjax(noticeService.updateNoticeByIds(ids));
    }
}
